import axios from 'axios'

import qs from 'qs'

const baseUrl = 'http://127.0.0.1:8080/'
const instance = axios.create({
  baseURL: baseUrl,
  timeout: 12000,
  withCredentials: false
})
instance.interceptors.request.use(function (config) {
  config.data = qs.stringify(config.data)
  if (sessionStorage.getItem('xixi_token')) {
    config.headers.xixi_token = sessionStorage.getItem('xixi_token')
  }
  return config
}, error => {
  // Do something with request error
  console.log(error) // for debug
  Promise.reject(error)
})

// 添加响应拦截器
instance.interceptors.response.use((response) => {
  // 对响应数据做点什么
  const data = response.data
  return data
}, function (error) {
  // 对响应错误做点什么
  return Promise.reject(error)
})
export default instance
